/**
 * 
 */
package com.thor.palmmall.rest.sales.input.converter;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.UCN;
import com.thor.commons.util.ConverterUtil;
import com.thor.palmmall.rest.sales.input.ASalesInput;
import com.thor.palmmall.spi.sales.input.SSalesInput4Create;

/**
 * @author NuoSa
 *
 * @since 1.0
 */
public class SSalesInput4CreateConverter implements Converter<ASalesInput, SSalesInput4Create> {

  public static SSalesInput4CreateConverter getInstance() {
    if (instance == null)
      instance = new SSalesInput4CreateConverter();
    return instance;
  }

  private static SSalesInput4CreateConverter instance;

  private SSalesInput4CreateConverter() {
  }

  @Override
  public SSalesInput4Create convert(ASalesInput source) {
    if (source == null) {
      return null;
    }
    SSalesInput4Create target = new SSalesInput4Create();
    target.setStore(UCN.newInstance(source.getStore()));
    target.setTenant(UCN.newInstance(source.getTenant()));
    target.setContract(UCN.newInstance(source.getContract()));
    target.setProduct(UCN.newInstance(source.getProduct()));
    target.setReceiver(source.getReceiver());
    target.setBalance(source.isBalance());
    target.setSaleDate(source.getSaleDate());
    target.setSaleCount(source.getSaleCount());
    target.setPayments(
        ConverterUtil.convert(source.getPayments(), SSalesInputLineConverter.getInstance()));
    target.setMediaFiles(source.getAttachments());
    target.setPermGroupId(source.getPermGroupId());
    target.setPermGroupTitle(source.getPermGroupTitle());
    return target;
  }

}
